﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using UFSSDesktopApp.UFSSservicereference;

namespace UFSSDesktopApp
{
    public partial class FormFiles : Form
    {
        private UFSSserviceSoapClient ussc;
        private UserCreds uc;
        private ArrayList files = new ArrayList();
        public void refresh()
        {
            files.Clear();
            lbFiles.Items.Clear();
            UFSSFile[] filearray = ussc.getFiles(uc);
            foreach (UFSSFile file in filearray)
            {
                files.Add(file);
                lbFiles.Items.Add(file.filename.ToString());
            }
        }
        
        public FormFiles(UFSSserviceSoapClient sc, UserCreds ucreds)
        {
            this.ussc = sc;
            this.uc = ucreds;
            InitializeComponent();
            refresh();
        }

        private void FormFiles_Load(object sender, EventArgs e)
        {
            
        }

        private void lbFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                UFSSFile tempfile;
                tempfile = (UFSSFile)files[lbFiles.SelectedIndex];
                lblTitle.Text = tempfile.filename.ToString();
                lblSize.Text = tempfile.filesize.ToString();
                lblDownloads.Text = tempfile.downloads.ToString();
            }
            catch
            { }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            Form.ActiveForm.Hide();
            FormMain fm = new FormMain(ussc, uc);
            fm.Activate();
            fm.Show();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ussc.delFile(uc, lbFiles.SelectedItem.ToString());
                //lbFiles.ClearSelected() ;
                refresh();
            }
            catch
            {
            }
        }
    }
}
